
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import pojo.Categories;
import util.HibernateUtil;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author CANHNGUYEN
 */
public class TestHibernate {

    public static void main(String[] args) {
        Session session = null;
        try {
            SessionFactory sessionFactory = new HibernateUtil().getSessionFactory();
            /* muon su dung phuong thuc getCurrentsession thi 
             * trong Hibernate configuration file cac ban phai khai bao thuoc tinh :
             * current_session_context_class co gia tri la : thread
             */
            /*
             * Neu khoong can lay current session thi 
             * cac ban co the dung phuong openSession de mo ra 1 session moi
             */
            session = sessionFactory.getCurrentSession();//openSession();//

            Categories cate = new Categories(101, "telsoft");
            session.beginTransaction();
            session.save(cate);
            session.getTransaction().commit();

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
